<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common :: header('WeiAdmin')"/>
    <link href="/admin/css/loader.css" rel="stylesheet"/>
    <link href="/admin/css/admin.css" rel="stylesheet"/>
    <style>
        .layui-upload-img {
            width: 92px;
            height: 92px;
        }

    </style>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" lay-filter="settingForm" action="" onsubmit="return false">
            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this">基础设置</li>
                    <li>其他</li>
                </ul>

                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">

                        <div class="layui-form-item">
                            <label class="layui-form-label">应用名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="app_name" required lay-verify="required"
                                       placeholder="请输入应用名称" autocomplete="off" class="layui-input"
                                       th:value="${info.app_name}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">LOGO</label>
                            <div class="layui-input-inline">
                                <button type="button" class="layui-btn" id="ID-upload-demo-btn">
                                    <i class="layui-icon layui-icon-upload"></i> 上传LOGo
                                </button>
                                <div style="width: 132px;">
                                    <div class="layui-upload-list">
                                        <input type="hidden" name="app_logo" id="thumb-input" th:value="${info.app_logo}">
                                        <img class="layui-upload-img" th:src="${info.app_logo}" id="ID-upload-demo-img" style="width: 100%; height: 92px;">
                                        <div id="ID-upload-demo-text"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">到期时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="app_endtime" id="app_endtime" required lay-verify="required"
                                       placeholder="请输入到期时间" autocomplete="off" class="layui-input"
                                       th:value="${info.app_endtime}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">开启审核</label>
                            <div class="layui-input-inline">
                                <input checked name="app_test" title="关闭" th:checked="${info.app_test eq '0'}"
                                       type="radio" value="0">
                                <input name="app_test" title="开启" th:checked="${info.app_test eq '1'}" type="radio"
                                       value="1">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">保存</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-form-item ">
                            <label class="layui-form-label">通知公告</label>
                            <div class="layui-input-inline">
                                <textarea name="notice" placeholder="请输入通知公告" class="layui-textarea" th:text="${info.notice}"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">保存</button>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </form>
    </div>
</div>
</div>
<th:block th:include="common :: footer"/>
<script>
    layui.use(['form','laydate','jquery','upload'], function(){
      var form = layui.form;
      let $ = layui.jquery;
      var laydate = layui.laydate;
      laydate.render({
        elem: '#app_endtime'
      });
      //设置上传相关
      var upload = layui.upload;
      var uploadInst = upload.render({
        elem: '#ID-upload-demo-btn',
        url: '/admin/public/upload',
        done: function(res){
            debugger;
            if(res.code == 0){
                return layer.msg('上传失败');
            }
            $("#ID-upload-demo-img").attr("src",res.data.url);
            $("#thumb-input").val(res.data.url);
        }
      });
      form.on('submit(formDemo)', function(data){
          debugger;
          $.ajax({
                url: '/admin/setting/update',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            //parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            //parent.layui.table.reload("role-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
          return false;
      });
    });
</script>
</body>
</html>